@model Lombiq.HelpfulExtensions.Extensions.ContentSets.ViewModels.ContentSetContentPickerFieldViewModel
@using OrchardCore
@using OrchardCore.ContentManagement.Metadata.Settings
@using OrchardCore.Mvc.Utilities
@using System.Text.Json.Nodes

@{
    var name = (Model.PartFieldDefinition.PartDefinition.Name + "-" + Model.PartFieldDefinition.Name).HtmlClassify();

    var settings = Model.PartFieldDefinition.Settings?.ToObject<ContentPartFieldSettings>();
    var displayName = settings?.DisplayName ?? Model.PartFieldDefinition.Name;

    var links = Model
        .MemberLinks
        .Where(link =>
            !link.IsDeleted &&
            link.ContentItemId != null &&
            link.ContentItemId != Model.ContentSetPart.ContentItem.ContentItemId)
        .ToList();
    if (!links.Any()) { return; }
}

<div class="field field-type-localizationsetpickerfield field-name-@name">
    <span class="name">@displayName</span>
    @for (var i = 0; i < links.Count; i++)
    {
        var link = links[i];
        var url = Orchard.GetItemDisplayUrl(link.ContentItemId);
        var separator = i < (links.Count - 1) ? ", " : string.Empty;
        <span class="value"><a href="@url">@link.DisplayText</a></span>@separator
    }
</div>
